<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=request.getContextPath()%>/css/base.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.tools.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.validate.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.validate.methods.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/base.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/admin.js"></script>
<script charset="utf-8" src="<%=request.getContextPath()%>/common/kindeditor/kindeditor.js"></script>

</head>


<BODY class="input goods" sizcache="0" sizset="0" ><DIV class=bar>添加商品 </DIV>
<div id="validateErrorContainer" class="validateErrorContainer">
		<div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
		<ul></ul>
	</div>

<DIV class=body sizcache="0" sizset="0">
<FORM id=goodsForm encType=multipart/form-data method=post action=goodssave.do sizcache="0" sizset="0" >
<UL id=tab class=tab>
<LI><INPUT hideFocus class=current value=基本信息 type=button> </LI>
<LI><INPUT hideFocus value=商品描述 type=button> </LI>
<LI><INPUT hideFocus value=商品图片 type=button> </LI>
<LI><INPUT hideFocus id=specificationTab value=商品规格 type=button> </LI>
</UL>
<TABLE  id=infoTable class="inputTable tabContent" sizcache="0" sizset="0" >
<TBODY sizcache="0" sizset="0">
<TR>
<TH>商品分类: </TH>
<TD><SELECT name=typeid onchange="changebrand(this)"> 
<OPTION selected value="">请选择...</OPTION> 
<c:forEach items="${toptypes}" var="goodstype">
       <OPTION value=${goodstype.id}>${goodstype.typeName}</OPTION> 
          <c:forEach items="${goodstype.underGoodTypes}" var="subgoodstype">
            <OPTION value=${subgoodstype.id}>&nbsp;&nbsp;&nbsp;&nbsp;${subgoodstype.typeName}</OPTION> 
            <c:forEach items="${subgoodstype.underGoodTypes}" var="tgoodstype">
              <OPTION value=${tgoodstype.id}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${tgoodstype.typeName}</OPTION> 
            </c:forEach>
          </c:forEach>
      </c:forEach>
</SELECT> <LABEL class=requireField>*</LABEL> </TD></TR>
<TR>
<TH>商品名称: </TH>
<TD><INPUT class=formText type=text name="goodsName" id=goodsName> <LABEL class=requireField>*</LABEL> </TD></TR>
<TR>
<TH>商品编号: </TH>
<TD><INPUT class=formText title=商品条码 type=text name=goodsNO> <LABEL class=requireField>*</LABEL> </TD></TR>
<TR>
<TH>品牌: </TH>
<TD><SELECT id=brandid name=brandid> <OPTION selected value="">请选择...</OPTION> 
</SELECT> </TD></TR>
<TR class=specificationDisabledInfo>
<TH>销售价: </TH>
<TD><INPUT class="formText valid"  type=text name=price> <LABEL class=requireField>*</LABEL> </TD></TR>
<TR class=specificationDisabledInfo>
<TH>成本价: </TH>
<TD><INPUT class=formText  type=text name=costPrice> <LABEL class=requireField>*</LABEL> </TD></TR>
<TR class=specificationDisabledInfo>
<TH>市场价: </TH>
<TD><INPUT class=formText  type=text name=historyPrice> <LABEL class=requireField>*</LABEL> </TD></TR>
<TR class=specificationDisabledInfo>
<TH>库存: </TH>
<TD><INPUT class=formText title=只允许输入零或正整数,为空表示不计库存 type=text name=goodsNum> <LABEL class=requireField>*</LABEL> </TD></TR>
<TR class=specificationDisabledInfo>
<TH>排序: </TH>
<TD><INPUT class=formText title=只允许输入零或正整数 type=text name=sort> </TD></TR>
<TR sizcache="0" sizset="0">
<TH>设置: </TH>
<TD sizcache="0" sizset="0">
<LABEL sizcache="0" sizset="0"><INPUT id=goodsIsMarketable value=1 CHECKED type=checkbox name=isMarketable>上架 </LABEL>
<LABEL sizcache="0" sizset="1"><INPUT id=goods_isBest value=1 type=checkbox name=isBest>精品 </LABEL>
<LABEL sizcache="0" sizset="2"><INPUT id=goods_isNew value=1 type=checkbox name=isNew>新品 </LABEL>
<LABEL sizcache="0" sizset="3"><INPUT id=goods_isHot value=1 type=checkbox name=isHot>热销 </LABEL>
</TD>
</TR>
<TR>
<TH>页面关键词: </TH>
<TD><INPUT class=formText type=text name=keyWorld> </TD></TR>
<TR>
<TH>页面描述: </TH>
<TD><TEXTAREA class=formTextarea name=description></TEXTAREA> </TD></TR></TBODY></TABLE>

<TABLE  class="inputTable tabContent"  >
<TBODY>
<TR>
<TD>
<textarea class="editor" cols="80" id="editor" name="editor" rows="10"></textarea>
</TD></TR></TBODY></TABLE>


<TABLE  id=goodsImageTable class="inputTable tabContent" >
<TBODY>
<TR class=noneHover>
<TD colSpan=5><INPUT hideFocus id=addGoodsImageButton class=formButton value=增加图片 type=button /> </TD></TR>
<TR class=title>
<TH>上传图片 </TH>
<TH>图片描述 </TH>
<TH>排序 </TH>
<TH>删除 </TH></TR></TBODY></TABLE>


<DIV  class=tabContent sizcache="0" sizset="4" >
<textarea  cols="80" id="format" name="format" rows="10"></textarea>
</DIV>


<DIV class=buttonArea><INPUT hideFocus class=formButton value="确  定" type=submit jQuery1357022562125="32">&nbsp;&nbsp; <INPUT hideFocus class=formButton onclick="window.history.back(); return false;" value="返  回" type=button> </DIV></FORM></DIV>
<DIV style="DISPLAY: none" class=ke-reset>&nbsp;</DIV>
<DIV style="FILTER: alpha(opacity=50)" class=ke-mask></DIV></BODY>

<script type="text/javascript">
KindEditor.ready(function(K) {
	K.create('textarea[name="editor"]', {
	    uploadJson : '<%=request.getContextPath()%>/common/kindeditor/jsp/upload_json.jsp',
		fileManagerJson : '<%=request.getContextPath()%>/common/kindeditor/jsp/file_manager_json.jsp',
		allowFileManager : true
	});
});


$().ready(function() {
    var $validateErrorContainer = $("#validateErrorContainer");
	var $validateErrorLabelContainer = $("#validateErrorContainer ul");
	var $tab = $("#tab");
	var $goodsForm = $("#goodsForm");
	var $specificationDisabledInfo = $("#infoTable .specificationDisabledInfo");
	var $goodsIsMarketable = $("#goodsIsMarketable");	
	var $goodsImageTable = $("#goodsImageTable");
	var $addGoodsImageButton = $("#addGoodsImageButton");
    

     // Tab效果
	$tab.tabs(".tabContent", {
		tabs: "input", onBeforeClick:function(index){  
            <c:if test="${empty goods}">
            if(index.srcElement)
            {
		     $.dialog({type: "warn", content: "请先保存商品基本信息!", modal: true, autoCloseTime: 3000});
		     return false;
		    }
		    </c:if>			
           return true;  
    }
	});
   
    
    // 增加商品图片
	var goodsImageIndex = 0;
	$addGoodsImageButton.click( function() {		
    var goodsImageTrHtml = '<tr class="goodsImageTr"> <td> <input type="file" name="goodsImageFileList[' + goodsImageIndex + ']" class="goodsImageFileList" /> </td> <td> <input type="text" name="goodsImageList[' + goodsImageIndex + '].description" class="formText" /> </td> <td> <input type="text" name="goodsImageList[' + goodsImageIndex + '].orderList" class="formText goodsImageOrderList" style="width: 50px;" /> </td> <td> <span class="deleteIcon deleteGoodsImage" title="删 除">&nbsp;</span> </td> </tr>';		
		$goodsImageTable.append(goodsImageTrHtml);
		goodsImageIndex ++;
	});
	
	// 删除商品图片
	$("#goodsImageTable .deleteGoodsImage").live("click", function(){
		var $this = $(this);
		$.dialog({type: "warn", content: "您确定要删除吗?", ok: "确 定", cancel: "取 消", modal: true, okCallback: deleteGoodsImage});
		function deleteGoodsImage() {
			$this.parent().parent().remove();
		}
	});
    
	// 表单验证
	$goodsForm.validate({	   
		errorClass: "validateError",   
		rules: {
			"goodType.id": "required",
			goodsName: "required",	
			goodsNO: {required: true,digits: true},	
			price: {required: true,number: true},	
			costPrice: {required: true,number: true},	
			historyPrice: {required: true,number: true},		
			goodsNum: {required: true,digits: true},
			sort: {required: true,digits: true}	
		},
		messages: {
			"goodType.id": "请选择商品类别!",
			goodsName: "请填写商品名称!",	
			goodsNO:{required:"请填写商品编号!",digits:"商品编号必需是正整数!"},	
			price:{required:"请填写商品售价!",number:"请填写合法的数字!"},				
			costPrice:{required:"请填写商品成本价!",number:"请填写合法的数字!"},		
			historyPrice:{required:"请填写商品市场价!",number:"请填写合法的数字!"},		
			goodsNum:{required:"请填写商品库存!",digits:"请填写合法的数字!"},
			sort:{required:"请填写商品排序!",digits:"请填写合法的数字!"}
		},
		submitHandler: function(form) {			   
			$(form).find(":submit").attr("disabled", true);
			form.submit();
		},
        errorPlacement: function(error, element) { 
            error.appendTo(element.parent()); 
        }
	});	
})


 function changebrand(type)
 {
   $("#brandid").empty();
   $("#brandid").prepend("<option value=''>请选择...</option>");  
   var typeid=type.value;
   if(typeid!='')
   { 
    var url='<%=request.getContextPath()%>/admin/querybrand.do?typeId='+typeid;
     $.get(url, function(result){	
        var brands=eval('('+result+')');	 
         for(i=0;i<brands.length;i++)
        {
          $("#brandid").append("<option value='"+brands[i].id+"'>"+brands[i].name+"</option>");   
        }
	   }); 
   
   }
 }
</script>
</html>